package com.teapos.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.teapos.web.BaseController;

@Component("sessionInterceptor")
public class SessionInterceptor implements HandlerInterceptor {
	
	@Override
	public boolean preHandle(HttpServletRequest req,
			HttpServletResponse res, Object handler) throws Exception {
		System.err.println("路过拦截器");
		System.err.println(req.getRequestURI());
		Object user = req.getSession().getAttribute(BaseController.LOGIN_USER);
		if(user==null) res.sendRedirect(req.getContextPath()+"/");
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest req,
			HttpServletResponse res, Object handler,
			ModelAndView modelAndView) throws Exception {
		
	}

	@Override
	public void afterCompletion(HttpServletRequest req,
			HttpServletResponse res, Object handler, Exception ex)
			throws Exception {
		
	}


}
